package pack;

import pack.FDP;
import pack.precomputation;
import pack.approximate;

/***
 * 
 * Main class of the project.
 * 
 * @author Paula C. Tataru, Marcus Schroeder
 *
 */
public class ProjectTwo {

	
	public static void main(String[] args){
		
		int[][] score_matrix = new int[4][4];
		score_matrix[0][0] = 0;score_matrix[0][1] = 5;score_matrix[0][2] = 2;score_matrix[0][3] = 5;
		score_matrix[1][0] = 5;score_matrix[1][1] = 0;score_matrix[1][2] = 5;score_matrix[1][3] = 2;
		score_matrix[2][0] = 2;score_matrix[2][1] = 5;score_matrix[2][2] = 0;score_matrix[2][3] = 5;
		score_matrix[3][0] = 5;score_matrix[3][1] = 2;score_matrix[3][2] = 5;score_matrix[3][3] = 0;

		
		double time_1 = 0;
		double time_2 = 0;
		double time_3 = 0;
		double time_4 = 0;
		double time_5 = 0;
		double time_6 = 0;
		double time_7 = 0;
		double time_8 = 0;
		int cost_1 = 0;
		int cost_2 = 0;
		int cost_3 = 0;
		int cost_4 = 0;
		int cost_5 = 0;
		int cost_6 = 0;
		int cost_7 = 0;
		int cost_8 = 0;
		int cells_3_a = 0;
		int cells_3_e = 0;
		int l = 10;
		int c = 4;	
		int runs = 10;
		int gapcost = 5;
		
		for(int k = 0; k < runs;k++){
		
			String[] seqs = new String[c];
			for(int i = 0; i < c; i ++){
				seqs[i] = IOHandler.createRandomDNASeq(l);
			}
			precomputation p_three = new precomputation(score_matrix,gapcost,seqs,c-1,l);
			precomputation p_four = new precomputation(score_matrix,gapcost,seqs,c,l);
			ExactMsaThreeSequences ets = new ExactMsaThreeSequences(seqs,IOHandler.readScoreMatrix("src/matrix.txt"), gapcost);
			time_1 += ets.getTime();
			cost_1 += ets.getCosts();
				
			approximate athree = new approximate(score_matrix, gapcost, seqs, c-1, l, p_three);
			time_2 += athree.getTime();
			cost_2 += athree.getCosts(); 
			
			FDP f_3_a = new FDP(score_matrix,gapcost,seqs,c-1,l,p_three);
            double time = System.nanoTime();
            f_3_a.run_upper_bound(null,athree.getCosts());
            time_5 += (System.nanoTime()-time)/1000000000;
            cost_5 += f_3_a.cost;
			cells_3_a += f_3_a.cells;
            
        	FDP f_3_e = new FDP(score_matrix,gapcost,seqs,c-1,l,p_three);
        	time = System.nanoTime();
            f_3_e.run_upper_bound(null,ets.getCosts());
            time_6 += (System.nanoTime()-time)/1000000000;
			cost_6 += f_3_e.cost;
			cells_3_e += f_3_e.cells;
			

			
			
			
			/*
			
			ExactMsaFourSequences efs = new ExactMsaFourSequences(seqs,IOHandler.readScoreMatrix("src/matrix.txt"), gapcost);
			time_3 += efs.getTime();
			cost_3 += efs.getCosts();
			approximate afour = new approximate(score_matrix, gapcost, seqs, c, l, p_four);
			time_4 += afour.getTime();
			cost_4 += afour.getCosts();*/
		}
		time_1 = time_1/runs;
		time_2 = time_2/runs;
		time_3 = time_3/runs;
		time_4 = time_4/runs;
		time_5 = time_5/runs;
		time_6 = time_6/runs;
		time_7 = time_7/runs;
		time_8 = time_8/runs;
		cost_1 = cost_1/runs;
		cost_2 = cost_2/runs;
		cost_3 = cost_3/runs;
		cost_4 = cost_4/runs;
		cost_5 = cost_5/runs;
		cost_6 = cost_6/runs;
		cost_7 = cost_7/runs;
		cost_8 = cost_8/runs;
		System.out.println("Three Sequences with length "+l);
		System.out.println("Avg. running time exact(3): "+time_1);
		System.out.println("Avg. running time approximated(3): "+time_2);
		System.out.println("Avg. running time fdp with approximated ub(3): "+time_5);
		System.out.println("Avg. running time fdp with exact ub(3): "+time_6);
		System.out.println("Avg. costs exact(3): "+cost_1);
		System.out.println("Avg. costs approximated(3): "+cost_2);
		System.out.println("Avg. costs fdp approximated(3): "+cost_5);
		System.out.println("Avg. costs fdp exact(3): "+cost_6);
		System.out.println("Avg. cells fdp app.(3): "+cells_3_a+"/"+(Math.pow(l, 3)));
		System.out.println("Avg. cells fdp exact(3): "+cells_3_e+"/"+(Math.pow(l,3)));
		
		System.out.println("");
		/*System.out.println("Four Sequences with length "+l);
		System.out.println("");
		System.out.println("Avg. running time exact(4): "+time_3);
		System.out.println("Avg. running time approximated(4): "+time_4);
		System.out.println("Avg. costs exact(4): "+cost_3);
		System.out.println("Avg. costs approximated(4): "+cost_4);
		*/
	}
	
}
